package ibmetp.mis.controller.email;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.email.EmailManager;
import ibmetp.mis.vo.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;


public class EmailSendServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public EmailSendServlet() {
        super();
    
    }


	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		String emails=request.getParameter("emails");
		String pwd=request.getParameter("pwd");
		String subject=request.getParameter("subject");
		String content=request.getParameter("content");
		User user=(User)request.getSession().getAttribute("userinfo");
		String result=EmailManager.send(user, pwd, emails,subject,content);
		if(result!=null)
		{
			//如果有返回消息，则将消息发回页面
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message("发送失败")));
		}
		
	}

}
